package com.sdl.timesblogmp.exception;

import com.sdl.timesblogmp.model.vo.ApiResult;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public ApiResult customException(CustomException e) {
        if (StringUtils.isEmpty(e.getCode())) {
            return ApiResult.error(e.getMessage());
        }

        return ApiResult.error(e.getCode(),e.getMessage());
    }

}
